package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.po.Teachplan;
import com.xuecheng.content.service.TeachPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description 课程计划编辑接口
 * @author Mr.M
 * @date 2022/9/6 11:29
 * @version 1.0
 */
 @Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
 @RestController
public class TeachplanController {

     @Autowired
     private TeachPlanService teachPlanService ;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId",name = "课程Id",required = true,dataType = "Long",paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        return teachPlanService.findTeachPlanTree(courseId);
    }


    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan( @RequestBody SaveTeachplanDto teachplan){
        teachPlanService.saveTeachPlan(teachplan);
    }

    @ApiOperation("课程删除")
    @DeleteMapping("/teachplan/{id}")
    public void deleteTeachPlan(@PathVariable Long id){
        teachPlanService.deleteTeachPlan(id);
    }

//    章节上移
    @PostMapping("/teachplan/moveup/{id}")
    public void moveupTeachPlan(@PathVariable Long id){
        teachPlanService.moveupTeachPlan(id);
    }

    //        章节下移
    @PostMapping("/teachplan/movedown/{id}")
    public void movedownTeachPlan(@PathVariable Long id){
        teachPlanService.movedownTeachPlan(id);
    }


    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachPlanService.associationMedia(bindTeachplanMediaDto);
    }

    @ResponseBody
    @ApiOperation(value = "获取课程计划小节信息")
    @PostMapping("/teachplan/getTeachplan/{id}")
    public Teachplan getTeachplan(@PathVariable("id") Long id){
        return teachPlanService.getTeachplan(id);
    }
}